package com.magic233.config.interceptor;

import com.magic233.interceptor.UsersInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName: Admin
 * Description:
 * date: 2021/5/12 11:10
 * author: zouyuan
 */
@Configuration
public class Users implements WebMvcConfigurer {
    @Bean
    public UsersInterceptor getUsersInterceptor() {
        return new UsersInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截user下的所有请求
        String[] addPathPatterns = {
                "/user/**"
        };

        //排除部分不需要登录的请求
        String[] excludePathPatterns = {
                "/user/login", "/user/resetPassword", "/user/noLogin", "/user/noPermissions", "/user/register", "/user/verifyId", "/user/verifyPhone", "/user/uploadImg","/user/uploadImgOne"
        };

        registry.addInterceptor(getUsersInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
